package com.experian.daas.litigation.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.experian.core.sharding.sqlsessiontemplate.CustomerContextHolder;
import com.experian.daas.litigation.dao.CartDao;
import com.experian.daas.litigation.entity.Cart;
import com.experian.daas.litigation.service.CartService;

@Service
public class CartServiceImpl implements CartService{
	@Resource
	private CartDao cartDao;
	
	
	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void addCart(Cart cart){
		CustomerContextHolder.setContextType("db2");
		cartDao.insert(cart);
	}
	
	@Override
	public List<Cart> getCarts(){
		CustomerContextHolder.setContextType("db2");
		return cartDao.selectAll();
	}
	
	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(Cart cart){
		CustomerContextHolder.setContextType("db2");
		cartDao.updateByPrimaryKey(cart);
		//int i=1/0;
	}
	
	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void addAndUpdate(){
		for(int i=40;i<50;i++){
			Cart cart = new Cart();
			cart.setId(i);
			cart.setType("y");
			cart.setCate("sss" + i);
			addCart(cart);
		}
		Cart c = new Cart();
		c.setId(1);
		c.setType("ccccc");
		update(c);
	}
	
	
}
